<template>
	<view class="warpbox">
		<!-- 搜索 -->
		<search-box @queryData="queryData" @showModal="showSc" placeholder="请输入锁号|锁内码|商品名称|商品编号搜索"></search-box>
		<scroll-view scroll-y class="scrollbox" @scrolltolower="loadMore">
			<view class="tip" v-if="total > 0">找到{{total}}个结果</view>
			<view class="tip" v-else>未查询到结果</view>
			<view class="pop_info_right">
				<view class="pop_info_cen" v-for="(item,index) in list" :key="index">
					<view class="pro_info">
						<view class="pro_top">
							<view class="info_text" style="font-size: 28rpx; color: #666;">{{item.serial}}</view>
							<view class="top_right success" v-if="item.store_status == 2">已出库</view>
							<view class="top_right primary" v-if="item.store_status == 1 && item.status != 3">在库</view>
							<view class="top_right error" v-if="item.store_status == 1 && item.status == 3">待出库</view>
						</view>
						<view class="info_text">商品：{{item.goods_name}}</view>
						<view class="info_text">锁内码：{{item.remark}}</view>
						<view class="info_text">所属仓库：{{item.stores_name}}</view>
						<view class="info_text" v-if="item.goods_salesid > 0">客户：<text class="customer" @click="toContractDetail(item)">{{item.customer_name}}</text></view>
					</view>
				</view>
				<view class="noData" v-if="list.length == 0">暂无更多</view>
			</view>
		</scroll-view>
		
		<screen-pop
			ref="screenChild" 
			@sureQuery="sureQuery"
			:searchForm="searchForm"
			:storeList="storeList"
			@changeSearchData="changeSearchData"
			@resetForm="resetForm"
		></screen-pop>
	</view>
</template>

<script>
	import { netGoodsSerial } from '@/api/api.js'
	import { BASE_IMG_URL } from '@/api/http.js'
	import screenPop from './screenPop.vue'
	
	export default{
		components:{
			screenPop
		},
		data(){
			return{
				BASE_IMG_URL:BASE_IMG_URL,
				list:[],
				page:1,
				totalPage:1,
				total:0,
				name:'',
				queryObj:{},
				searchForm:null,  //搜索表单
				defaultObj:{type:'',store_status:'', storeid:0},
				storeList:[]
			}
		},
		onLoad(options) {
			if(options.type){
				this.defaultObj = options
			}
			//获取搜索表单
			this.getSearchForm()
		},
		onShow() {
			this.page = 1
			this.list = []
			this.getList()
		},
		onReachBottom() {
			console.log('onReachBottom',this.page,this.totalPage)
			if(this.page >= this.totalPage){
				return
			}
			this.page ++
			this.getList()
		},
		methods:{
			queryData(e) {
				this.name = e.value
				this.page = 1
				this.list = []
				this.getList()
			},
			getList() {
				let params = {
					page:this.page,
					name:this.name,
					type:this.defaultObj.type,
					createtime:this.defaultObj.times,
					store_status:this.defaultObj.store_status,
					stores_id:this.defaultObj.storeid,
					...this.queryObj,
					...this.handleSureSearch(this.searchForm)
				}
				netGoodsSerial(params).then(res=>{
					this.list = this.list.concat(res.data.data)
					this.totalPage = res.data.last_page
					this.total = res.data.total
					this.storeList = res.data.stores
				})
			},
			
			loadMore() {
				if(this.page >= this.totalPage){
					return
				}
				this.page ++
				this.getList()
			},
			toContractDetail(item){
				uni.navigateTo({
					url:'/pages/index/contractManagements/contractDetail?id='+item.goods_salesid+'&purchase_code='+item.sale_code
				})
			},
			//搜索表单
			getSearchForm() {
				this.handleSearchForm('serials',(data)=>{
					this.searchForm = data
				})
			},
			changeSearchData(type,key,value){
				let arr = this.searchForm
				arr.forEach((ele,index)=>{
					if(ele.field == type){
						ele[key] = value
						this.$set(this.searchForm, index, ele)
					}
				})
			},
			resetForm() {
				this.searchForm = this.handleResetSearch(this.searchForm)
			},
			showSc() {
				this.$refs.screenChild.open(this.defaultObj)
			},
			sureQuery(params) {
				this.queryObj = params
				this.defaultObj = {
					type: params.type,
					times: params.createtime,
					store_status: params.store_status,
					storeid: params.storeid
				}
				this.page = 1
				this.list = []
				this.getList()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.searbox{
		padding:10rpx 0 20rpx 0;
		display: flex;
		justify-content: center;
		align-items: center;
		background:$uni-top-bg-color;
		.censear{
			display: flex;
			justify-content: flex-start;
			align-items: center;
			padding:0 24rpx;
			border-radius: 34rpx;
			background:#FFFFFF;
			width:488rpx;
			height:68rpx;
			.searimg{
				padding-right: 15rpx;
				width:35rpx;
				height:35rpx;
			}
			.lself{
				font-size:26rpx;
			}
		}
	}
	.scrollbox{
		width:750rpx;
		height:calc(100vh - 110rpx);
	}
	.tip{
		padding:15rpx 26rpx 0;
		font-size:24rpx;
		color:#008EFF;
		text-align: center;
	}
	.pop_info_right{
		padding:24rpx 0;
		.pop_info_cen{
			width: 690rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 7rpx 0px rgba(0, 0, 0, 0.15);
			border-radius: 10rpx;
			margin:24rpx auto 0;
		}
		
		.pro_title{
			padding:24rpx 0;
			font-size:30rpx;
			color:#333333;
		}
		.pro_top{
			display: flex;
			justify-content: space-between;
			margin-bottom:15rpx;
			.top_right{
				font-size:24rpx;
				min-width:100rpx;
				height:45rpx;
				text-align: center;
				line-height: 45rpx;
				border-radius: 10rpx;
				padding: 0 6rpx;
				background:$uni-bg-opacity;
				// color:$uni-text-color;
			}
		}
		.pro_info{
			padding:24rpx;
			.info_text{
				font-size:26rpx;
				color:#999999;
				margin-bottom:14rpx;
				&:last-child{
					margin-bottom:0;
				}
				.customer{
					color:$uni-text-color;
				}
			}
		}
		.pro_num{
			font-size:28rpx;
			color:#0287FF;
			padding:24rpx 0;
		}
	}
	.icon_creat {
		position: fixed;
		z-index: 1;
		bottom: 100rpx;
		right: 100rpx;
		image {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
		}
	}
	.primary{
		color:$uni-color-primary
	};
	.success{
		color:$uni-color-success
	};
	.error{
		color:$uni-color-error
	};
</style>